define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'recruit/recruit/index' + location.search,
                    add_url: 'recruit/recruit/add',
                    edit_url: 'recruit/recruit/edit',
                    del_url: 'recruit/recruit/del',
                    multi_url: 'recruit/recruit/multi',
                    import_url: 'recruit/recruit/import',
                    table: 'recruit',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'users.nickname', title: __('Users_id'),operate: false},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        // {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'salary', title: __('Salary'), operate: 'LIKE'},
                        {field: 'class.name', title: __('Class_id'),operate: false},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('Sex 0'),"1":__('Sex 1')}, formatter: Table.api.formatter.normal},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'wx_code', title: __('Wx_code'), operate: 'LIKE'},
                        {field: 'qq_code', title: __('Qq_code'), operate: 'LIKE'},
                        {field: 'whats_code', title: __('Whats_code'), operate: 'LIKE'},
                        // {field: 'hot', title: __('Hot')},
                        {field: 'browse', title: __('Browse')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 启动和暂停按钮
            $(document).on("click", ".btn-start", function () {
                //在table外不可以使用添加.btn-change的方法
                //只能自己调用Table.api.multi实现
                //如果操作全部则ids可以置为空
                var ids = Table.api.selectedids(table);
                Table.api.multi("changestatus", ids.join(","), table, this);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
